package com.pandy.code;

import com.pandy.code.Node;

/**
 * @description:
 * @author: panhong
 * @date: 2025/3/26
 */
public class Code10_List_Reversal {

    public static Node reversal(Node head) {
        if(head == null || head.next == null) {
            return head;
        }

        Node node1 = head.next;
        head.next = null;
        Node node2 = null;
        while (node1 != null) {
            node2 = node1.next;
            node1.next = head;
            head = node1;
            node1 = node2;
        }
        return head;
    }

    public static void main(String[] args) {
        Node n1 = new Node(1);
        Node n2 = new Node(2);
        Node n3 = new Node(3);
        Node n4 = new Node(4);
        Node n5 = new Node(5);
        Node n6 = new Node(6);

        n1.next = n2;
        n2.next = n3;
        n3.next = n4;
        n4.next = n5;
        n5.next = n6;

        System.out.println(reversal(n1).value);
    }
}
